/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-09-02
 * Time: 20:31
 */

/**
 * 有三个线程，线程名称分别为：a，b，c。
 * 每个线程打印自己的名称
 * 需要让他们同时启动，并按 c，b，a的顺序打印
 */
public class demo2 {

    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread c = new Thread(() -> {
            System.out.println("c");
            synchronized (locker1) {
                locker1.notify();//唤醒b,该打印b了
            }
        });
        Thread b = new Thread(() -> {
            synchronized (locker1) {
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("b");
            synchronized (locker2) {
                locker2.notify();//唤醒a
            }
        });
        Thread a = new Thread(() -> {
            synchronized (locker2) {
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("a");
        });
        a.start();
        b.start();
        c.start();

    }
}
